﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using APP.HELPER;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms; using Common;
    using Dictionary.ERP;

    public class xucSchedule : Common.xucBase
    {
        private CheckEdit cheIsAutomatic;
        private IContainer components;
        private GroupBox groupBox3;
        private LabelControl labelControl1;
        private LabelControl labelControl10;
        private LabelControl labelControl11;
        private LabelControl labelControl2;
        private LabelControl labelControl3;
        private LabelControl labelControl4;
        private LabelControl labelControl5;
        private LabelControl labelControl6;
        private LabelControl labelControl7;
        private LabelControl labelControl8;
        private LabelControl labelControl9;
        private DataTable m_DataTableEmployee;
        private string m_EmployeeCode;
        private TextEdit txtCN;
        private TextEdit txtT2;
        private TextEdit txtT3;
        private TextEdit txtT4;
        private TextEdit txtT5;
        private TextEdit txtT6;
        private TextEdit txtT7;
        private LabelControl txtTimeHour;

        public xucSchedule()
        {
            this.m_EmployeeCode = "";
            this.components = null;
            this.InitializeComponent();
            this.InitSymbol();
        }

        public xucSchedule(DataTable DataTableEmployee)
        {
            this.m_EmployeeCode = "";
            this.components = null;
            this.InitializeComponent();
            this.m_DataTableEmployee = DataTableEmployee;
            this.InitSymbol();
            this.LoadSchedule(this.m_DataTableEmployee.Rows[0]["EmployeeCode"].ToString());
        }

        public xucSchedule(string EmployeeCode)
        {
            this.m_EmployeeCode = "";
            this.components = null;
            this.InitializeComponent();
            this.m_EmployeeCode = EmployeeCode;
            this.InitSymbol();
            this.LoadSchedule(this.m_EmployeeCode);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucSchedule));
            this.groupBox3 = new GroupBox();
            this.cheIsAutomatic = new CheckEdit();
            this.labelControl1 = new LabelControl();
            this.labelControl11 = new LabelControl();
            this.txtTimeHour = new LabelControl();
            this.labelControl10 = new LabelControl();
            this.labelControl9 = new LabelControl();
            this.labelControl8 = new LabelControl();
            this.labelControl6 = new LabelControl();
            this.labelControl7 = new LabelControl();
            this.labelControl4 = new LabelControl();
            this.labelControl5 = new LabelControl();
            this.labelControl3 = new LabelControl();
            this.labelControl2 = new LabelControl();
            this.txtCN = new TextEdit();
            this.txtT7 = new TextEdit();
            this.txtT6 = new TextEdit();
            this.txtT5 = new TextEdit();
            this.txtT4 = new TextEdit();
            this.txtT3 = new TextEdit();
            this.txtT2 = new TextEdit();
            this.groupBox3.SuspendLayout();
            this.cheIsAutomatic.Properties.BeginInit();
            this.txtCN.Properties.BeginInit();
            this.txtT7.Properties.BeginInit();
            this.txtT6.Properties.BeginInit();
            this.txtT5.Properties.BeginInit();
            this.txtT4.Properties.BeginInit();
            this.txtT3.Properties.BeginInit();
            this.txtT2.Properties.BeginInit();
            base.SuspendLayout();
            this.groupBox3.Controls.Add(this.cheIsAutomatic);
            this.groupBox3.Controls.Add(this.labelControl1);
            this.groupBox3.Controls.Add(this.labelControl11);
            this.groupBox3.Controls.Add(this.txtTimeHour);
            this.groupBox3.Controls.Add(this.labelControl10);
            this.groupBox3.Controls.Add(this.labelControl9);
            this.groupBox3.Controls.Add(this.labelControl8);
            this.groupBox3.Controls.Add(this.labelControl6);
            this.groupBox3.Controls.Add(this.labelControl7);
            this.groupBox3.Controls.Add(this.labelControl4);
            this.groupBox3.Controls.Add(this.labelControl5);
            this.groupBox3.Controls.Add(this.labelControl3);
            this.groupBox3.Controls.Add(this.labelControl2);
            this.groupBox3.Controls.Add(this.txtCN);
            this.groupBox3.Controls.Add(this.txtT7);
            this.groupBox3.Controls.Add(this.txtT6);
            this.groupBox3.Controls.Add(this.txtT5);
            this.groupBox3.Controls.Add(this.txtT4);
            this.groupBox3.Controls.Add(this.txtT3);
            this.groupBox3.Controls.Add(this.txtT2);
            this.groupBox3.Location = new Point(10, 10);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new Size(0x2b0, 0x1a5);
            this.groupBox3.TabIndex = 4;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "Lịch tr\x00ecnh l\x00e0m việc trong tuần (theo ca)";
            this.cheIsAutomatic.Location = new Point(14, 360);
            this.cheIsAutomatic.Name = "cheIsAutomatic";
            this.cheIsAutomatic.Properties.Caption = "Tự động nhận ca khi duyệt dữ liệu từ m\x00e1y chấm c\x00f4ng.";
            this.cheIsAutomatic.Size = new Size(0x28e, 0x13);
            this.cheIsAutomatic.TabIndex = 0x12;
            this.labelControl1.AllowHtmlString = true;
            this.labelControl1.Appearance.Options.UseTextOptions = true;
            this.labelControl1.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl1.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl1.Location = new Point(0x10, 380);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(0x29a, 0x20);
            this.labelControl1.TabIndex = 0x13;
            this.labelControl1.Text = "<i>(Kh\x00f4ng khuyến kh\x00edch sử dụng, c\x00f3 thể dẫn đến sai s\x00f3t dữ liệu. Chỉ sử dụng trong trường hợp nh\x00e2n vi\x00ean l\x00e0m việc theo ca m\x00e0 kh\x00f4ng c\x00f3 một lịch tr\x00ecnh cụ thể trong tuần)</i>";
            this.labelControl11.AllowHtmlString = true;
            this.labelControl11.Appearance.Options.UseTextOptions = true;
            this.labelControl11.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl11.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl11.Location = new Point(0x12, 0x3e);
            this.labelControl11.Name = "labelControl11";
            this.labelControl11.Size = new Size(650, 0x15);
            this.labelControl11.TabIndex = 0x11;
            this.labelControl11.Text = "Để thiết lập mặc định nhiều ca l\x00e0m việc trong ng\x00e0y ta nhập:  <i>M\x00e3 ca 1, M\x00e3 ca 2, M\x00e3 ca 3,...</i>";
            this.txtTimeHour.AllowHtmlString = true;
            this.txtTimeHour.Appearance.Options.UseTextOptions = true;
            this.txtTimeHour.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.txtTimeHour.AutoSizeMode = LabelAutoSizeMode.None;
            this.txtTimeHour.Location = new Point(0x18e, 0x5f);
            this.txtTimeHour.Name = "txtTimeHour";
            this.txtTimeHour.Size = new Size(250, 0xcf);
            this.txtTimeHour.TabIndex = 0x10;
            this.txtTimeHour.Text = "<b>[] M\x00e3 ca:</b>";
            this.labelControl10.Appearance.Options.UseTextOptions = true;
            this.labelControl10.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl10.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl10.Location = new Point(0x11, 0x13c);
            this.labelControl10.Name = "labelControl10";
            this.labelControl10.Size = new Size(0x28d, 0x20);
            this.labelControl10.TabIndex = 15;
            this.labelControl10.Text = "Phần mềm sẽ tự động xếp ca tương ứng với thứ của k\x00fd hiệu chấm c\x00f4ng m\x00e0 bạn nhập ở tr\x00ean mỗi khi bảng xếp ca th\x00e1ng mới được ph\x00e1t sinh.";
            this.labelControl9.AllowHtmlString = true;
            this.labelControl9.Appearance.Options.UseTextOptions = true;
            this.labelControl9.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.labelControl9.AutoSizeMode = LabelAutoSizeMode.None;
            this.labelControl9.Location = new Point(0x11, 0x13);
            this.labelControl9.Name = "labelControl9";
            this.labelControl9.Size = new Size(0x28d, 0x29);
            this.labelControl9.TabIndex = 14;
            this.labelControl9.Text = manager.GetString("labelControl9.Text");
            this.labelControl8.Location = new Point(0xa1, 0x11d);
            this.labelControl8.Name = "labelControl8";
            this.labelControl8.Size = new Size(0x30, 13);
            this.labelControl8.TabIndex = 13;
            this.labelControl8.Text = "Chủ nhật:";
            this.labelControl6.Location = new Point(0xa1, 0xfe);
            this.labelControl6.Name = "labelControl6";
            this.labelControl6.Size = new Size(0x20, 13);
            this.labelControl6.TabIndex = 12;
            this.labelControl6.Text = "Thứ 7:";
            this.labelControl7.Location = new Point(0xa1, 0xdf);
            this.labelControl7.Name = "labelControl7";
            this.labelControl7.Size = new Size(0x20, 13);
            this.labelControl7.TabIndex = 11;
            this.labelControl7.Text = "Thứ 6:";
            this.labelControl4.Location = new Point(0xa1, 0xbf);
            this.labelControl4.Name = "labelControl4";
            this.labelControl4.Size = new Size(0x20, 13);
            this.labelControl4.TabIndex = 10;
            this.labelControl4.Text = "Thứ 5:";
            this.labelControl5.Location = new Point(0xa1, 160);
            this.labelControl5.Name = "labelControl5";
            this.labelControl5.Size = new Size(0x20, 13);
            this.labelControl5.TabIndex = 9;
            this.labelControl5.Text = "Thứ 4:";
            this.labelControl3.Location = new Point(0xa1, 130);
            this.labelControl3.Name = "labelControl3";
            this.labelControl3.Size = new Size(0x20, 13);
            this.labelControl3.TabIndex = 8;
            this.labelControl3.Text = "Thứ 3:";
            this.labelControl2.Location = new Point(0xa1, 0x63);
            this.labelControl2.Name = "labelControl2";
            this.labelControl2.Size = new Size(0x20, 13);
            this.labelControl2.TabIndex = 7;
            this.labelControl2.Text = "Thứ 2:";
            this.txtCN.Location = new Point(0xd9, 0x11a);
            this.txtCN.Name = "txtCN";
            this.txtCN.Size = new Size(0x9f, 20);
            this.txtCN.TabIndex = 6;
            this.txtT7.Location = new Point(0xd9, 0xfb);
            this.txtT7.Name = "txtT7";
            this.txtT7.Size = new Size(0x9f, 20);
            this.txtT7.TabIndex = 5;
            this.txtT6.Location = new Point(0xd9, 220);
            this.txtT6.Name = "txtT6";
            this.txtT6.Size = new Size(0x9f, 20);
            this.txtT6.TabIndex = 4;
            this.txtT5.Location = new Point(0xd9, 0xbc);
            this.txtT5.Name = "txtT5";
            this.txtT5.Size = new Size(0x9f, 20);
            this.txtT5.TabIndex = 3;
            this.txtT4.Location = new Point(0xd9, 0x9d);
            this.txtT4.Name = "txtT4";
            this.txtT4.Size = new Size(0x9f, 20);
            this.txtT4.TabIndex = 2;
            this.txtT3.Location = new Point(0xd9, 0x7f);
            this.txtT3.Name = "txtT3";
            this.txtT3.Size = new Size(0x9f, 20);
            this.txtT3.TabIndex = 1;
            this.txtT2.Location = new Point(0xd9, 0x60);
            this.txtT2.Name = "txtT2";
            this.txtT2.Size = new Size(0x9f, 20);
            this.txtT2.TabIndex = 0;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.groupBox3);
            base.Name = "xucSchedule";
            base.Padding = new Padding(10);
            base.Size = new Size(0x2c4, 0x1ba);
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            this.cheIsAutomatic.Properties.EndInit();
            this.txtCN.Properties.EndInit();
            this.txtT7.Properties.EndInit();
            this.txtT6.Properties.EndInit();
            this.txtT5.Properties.EndInit();
            this.txtT4.Properties.EndInit();
            this.txtT3.Properties.EndInit();
            this.txtT2.Properties.EndInit();
            base.ResumeLayout(false);
        }

        private void InitSymbol()
        {
            DIC_SHIFT dic_shift = new DIC_SHIFT();
            foreach (DataRow row in dic_shift.GetList().Rows)
            {
                if (row["ShiftCode"].ToString() != "")
                {
                    this.txtTimeHour.Text = this.txtTimeHour.Text + Environment.NewLine + Environment.NewLine + row["ShiftCode"].ToString() + " <i>(" + DateTime.Parse(row["BeginTime"].ToString()).ToString("HH:mm") + "-" + DateTime.Parse(row["EndTime"].ToString()).ToString("HH:mm") + ");</i>  ";
                }
            }
        }

        private void LoadSchedule(string EmployeeCode)
        {
            try
            {
                HRM_EMPLOYEE_SCHEDULE hrm_employee_schedule = new HRM_EMPLOYEE_SCHEDULE();
                hrm_employee_schedule.Get(EmployeeCode);
                this.txtT2.Text = hrm_employee_schedule.T2;
                this.txtT3.Text = hrm_employee_schedule.T3;
                this.txtT4.Text = hrm_employee_schedule.T4;
                this.txtT5.Text = hrm_employee_schedule.T5;
                this.txtT6.Text = hrm_employee_schedule.T6;
                this.txtT7.Text = hrm_employee_schedule.T7;
                this.txtCN.Text = hrm_employee_schedule.CN;
                this.cheIsAutomatic.Checked = hrm_employee_schedule.IsAutomatic;
            }
            catch
            {
            }
        }

        public void Save()
        {
            if (this.m_EmployeeCode == "")
            {
                this.Save(this.m_DataTableEmployee);
            }
            else
            {
                this.Save(this.m_EmployeeCode);
            }
        }

        public void Save(DataTable DataTableEmployee)
        {
            foreach (DataRow row in DataTableEmployee.Rows)
            {
                this.Save(row["EmployeeCode"].ToString());
            }
        }

        public void Save(string EmployeeCode)
        {
            new HRM_EMPLOYEE_SCHEDULE { EmployeeCode = EmployeeCode, T2 = this.txtT2.Text, T3 = this.txtT3.Text, T4 = this.txtT4.Text, T5 = this.txtT5.Text, T6 = this.txtT6.Text, T7 = this.txtT7.Text, CN = this.txtCN.Text, IsAutomatic = this.cheIsAutomatic.Checked }.Update();
        }
    }
}

